﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProjectForm.ascx.cs"
    Inherits="WEB.APP.Controls.List.ProjectForm" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:XScript ID="XScript1" runat="server">
    <script language="javascript" type="text/javascript">
        function SaveData() {
            var records = #{grdExpertise}.store.data;
            var jsonData1 = '';
            var _flag = true;
            for (var i = 0; i < records.length; i++) {
                if (i == records.length - 1) {
                    jsonData1 += Ext.encode(records.items[i].data);
                } else {
                    jsonData1 += Ext.encode(records.items[i].data) + ',';
                }
                if (records.items[i].data.Checked === true)
                    _flag = false;
            }
            if (_flag) {
                Ext.Msg.alert('Notification', 'Please select at least one Expertise!');
                return;
            }
            if (jsonData1 != '') {
                jsonData1 = "[" + jsonData1 + "]";
            }

            records = #{stStudent}.data;
            var jsonData2 = '';
            for (var i = 0; i < records.length; i++) {
                if (i == records.length - 1) {
                    jsonData2 += Ext.encode(records.items[i].data);
                } else {
                    jsonData2 += Ext.encode(records.items[i].data) + ',';
                }
            }
            if (jsonData2 != '') {
                jsonData2 = "[" + jsonData2 + "]";
            }
            #{DirectMethods}.SaveData(jsonData1,jsonData2);
        }

        function SelectClient(e, record, index) {
            #{tfClientName}.setValue(record.data.ClientName);
        }

        var tfAddSkillClick = function(f, parter, index, text, e) {
            if (index===0) {
                if (f.getValue().length > 0) {
                    #{taOtherSkill}.setValue(#{taOtherSkill}.getValue() + #{taOtherSkill}.getValue().split('\n').length + '. ' + f.getValue() + '\n');
                    f.reset();
                    f.focus();
                }
            }
            else if (index===1) {
                #{taOtherSkill}.reset();
            }
        }

        function KeyEnterAdd(f, e) {
            if (e.getKey() === e.ENTER) {
                if (f.getValue().length > 0) {
                    #{taOtherSkill}.setValue(#{taOtherSkill}.getValue() + #{taOtherSkill}.getValue().split('\n').length + '. ' + f.getValue() + '\n');
                    f.reset();
                    f.focus();
                    return false;
                }
            }
            return true;
        }

        var AddStudent = function (f, parter, index, text, e) {
            if (f.selectedIndex === -1)
                return;

            for (var i = 0; i < #{stStudent}.data.length; i++) {
                if (#{stStudent}.data.items[i].data.StudentId === f.store.data.items[f.selectedIndex].data.StudentId) {
                    Ext.Msg.alert('Notification', 'This student is already exists');
                    f.reset();
                    return;
                }
            }
            #{stStudent}.addRecord(f.store.data.items[f.selectedIndex].json);
            #{cbStudentID}.reset();
        }

        var DeleteStudent = function () {
            if (#{gpStudent}.selModel.selections.length === 0)
                return;

            var record = #{gpStudent}.selModel.selections.items[0];
            Ext.Msg.confirm('Delete the data', 'Are you sure you want to remove the student ' + record.data.StudentId + ' ?', function (btn) {
                if (btn==='yes') {
                    #{stStudent}.remove(record);
                    //WindowEditor_gpStudent.view.refresh();
                }
            });
        }
        
        var RendererProjectTypeS = function (value) {
            if (value === null || value === '')
                return value;
            var _temp = '';
            var _items = value.split(',');
            for (var i = 0; i < _items.length; i++) {
                if (_items[i] === null || _items[i] === '')
                    continue;

                switch (_items[i]) {
//                    case '1':
//                        _temp += 'Database Design and Development' + ', ';
//                        continue;
//                    case '2':
//                        _temp += 'Software Development' + ', ';
//                        continue;
//                    case '3':
//                        _temp += 'Mobile Application' + ', ';
//                        continue;
//                    case '4':
//                        _temp += 'Web Application' + ', ';
//                        continue;
//                    case '5':
//                        _temp += 'Systems Analysis and Design' + ', ';
//                        continue;
//                    case '6':
//                        _temp += 'Website Design and Development' + ', ';
//                        continue;
//                    case '7':
//                        _temp += 'Systems Administration' + ', ';
//                        continue;
//                    case '8':
//                        _temp += 'Operating System Development' + ', ';
//                        continue;
//                    case '9':
//                        _temp += 'Web Systems development' + ', ';
//                        continue;
                    case '1':
                        _temp += 'DD&D' + ', ';
                        continue;
                    case '2':
                        _temp += 'SD' + ', ';
                        continue;
                    case '3':
                        _temp += 'MA' + ', ';
                        continue;
                    case '4':
                        _temp += 'WA' + ', ';
                        continue;
                    case '5':
                        _temp += 'SA&D' + ', ';
                        continue;
                    case '6':
                        _temp += 'WD&D' + ', ';
                        continue;
                    case '7':
                        _temp += 'SA' + ', ';
                        continue;
                    case '8':
                        _temp += 'OSD' + ', ';
                        continue;
                    case '9':
                        _temp += 'WSD' + ', ';
                        continue;
                    default:
                        _temp += _items[i] + ', ';
                        continue;
                }
            }
            return _temp.substring(0, _temp.length - 2);
        }
    </script>
</ext:XScript>
<ext:Window ID="winDetails" runat="server" Title="Project Detail" Frame="false" Hidden="true"
    CenterOnLoad="true" Width="710" BodyStyle="padding:5px 5px 0px 5px;" Resizable="false"
    Closable="true" Layout="Fit" AutoHeight="true" Icon="Group" IDMode="Inherit"
    Modal="true">
    <Items>
        <ext:FormPanel ID="FormPanel1" runat="server" Header="false" Border="false" MonitorValid="true"
            BodyStyle="background-color:transparent;" Layout="FormLayout" AutoHeight="true"
            Split="true">
            <Items>
                <ext:Hidden ID="hfProjectId" runat="server" />
                <ext:DisplayField ID="DisplayField1" runat="server" Text="<span style='color: Red;'>*</span> is Required field" HideLabel="True" />
                <ext:Panel runat="server" BodyStyle="background-color:transparent;" Layout="ColumnLayout"
                    Border="False" Height="395" Split="true">
                    <Items>
                        <ext:Panel runat="server" ColumnWidth="0.5" BodyStyle="background-color:transparent;"
                            Layout="FormLayout" Border="False" LabelWidth="85">
                            <Defaults>
                                <ext:Parameter Name="Anchor" Value="99%" />
                            </Defaults>
                            <Items>
                                <ext:FieldSet runat="server" Layout="FormLayout" Padding="8" AutoHeight="true">
                                    <Defaults>
                                        <ext:Parameter Name="Anchor" Value="100%" />
                                    </Defaults>
                                    <Items>
                                        <ext:ComboBox ID="cbClientID" runat="server" DisplayField="ClientId" ValueField="ClientId"
                                            TypeAhead="false" ItemSelector="tr.list-item" MinChars="1" Width="150" SelectOnFocus="true"
                                            TriggerAction="All" EnableKeyEvents="true" FieldLabel="Client Id<span style='color: Red;'>*</span>" AllowBlank="false">
                                            <Store>
                                                <ext:Store ID="stClient" runat="server" AutoLoad="true">
                                                    <Proxy>
                                                        <ext:HttpProxy Method="POST" Url="/Modules/List/Search.ashx" DisableCaching="true"
                                                            AutoDataBind="true" />
                                                    </Proxy>
                                                    <Reader>
                                                        <ext:JsonReader Root="Search" TotalProperty="total" IDProperty="ClientId">
                                                            <Fields>
                                                                <ext:RecordField Name="ClientId" />
                                                                <ext:RecordField Name="ClientName" />
                                                                <ext:RecordField Name="BirthDt" Type="Date" />
                                                            </Fields>
                                                        </ext:JsonReader>
                                                    </Reader>
                                                    <BaseParams>
                                                        <ext:Parameter Name="type" Value="ClientLoadProject" Mode="Value" />
                                                    </BaseParams>
                                                </ext:Store>
                                            </Store>
                                            <Template ID="Template2" runat="server">
                                                <Html>
                                                    <tpl for=".">
                                                    <tpl if="[xindex] == 1">
                                                        <table class="cbStates-list" width="100%">
                                                    </tpl>
                                                    <tr class="list-item">
                                                        <td width="40px" style="padding:3px 0px;">{ClientId}</td>
                                                        <td width="40px" style="padding:3px 0px;">{ClientName}</td>
                                                    </tr>
                                                    <tpl if="[xcount-xindex]==0"> 
                                                        </table>
                                                    </tpl>
                                                </tpl>
                                                </Html>
                                            </Template>
                                            <Listeners>
                                                <Select Fn="SelectClient" />
                                            </Listeners>
                                        </ext:ComboBox>
                                        <ext:TextField runat="server" ID="tfClientName" FieldLabel="Client Name" Disabled="true" />
                                    </Items>
                                </ext:FieldSet>
                                <ext:FieldSet runat="server" Layout="FormLayout" Padding="8" AutoHeight="true">
                                    <Defaults>
                                        <ext:Parameter Name="Anchor" Value="100%" />
                                    </Defaults>
                                    <Items>
                                        <ext:TextField runat="server" ID="tfProjectName" FieldLabel="Project Name<span style='color: Red;'>*</span>" AllowBlank="false">
                                        </ext:TextField>
                                        <ext:ComboBox runat="server" ID="cbProjectType" FieldLabel="Project Type<span style='color: Red;'>*</span>" Editable="false"
                                            AllowBlank="false">
                                            <Items>
                                                <ext:ListItem Text="Database Design and Development" Value="1" />
                                                <ext:ListItem Text="Software Development" Value="2" />
                                                <ext:ListItem Text="Mobile Application" Value="3" />
                                                <ext:ListItem Text="Web Application" Value="4" />
                                                <ext:ListItem Text="Systems Analysis and Design" Value="5" />
                                                <ext:ListItem Text="Website Design and Development" Value="6" />
                                                <ext:ListItem Text="Systems Administration" Value="7" />
                                                <ext:ListItem Text="Operating System Development" Value="8" />
                                                <ext:ListItem Text="Web Systems development" Value="9" />
                                            </Items>
                                        </ext:ComboBox>
                                        <ext:ComboBox runat="server" ID="cbProjectSize" FieldLabel="Project Size<span style='color: Red;'>*</span>" Editable="false"
                                            AllowBlank="false">
                                            <Items>
                                                <ext:ListItem Text="Easy" Value="0" />
                                                <ext:ListItem Text="Medium complexity" Value="1" />
                                                <ext:ListItem Text="Complex" Value="2" />
                                            </Items>
                                        </ext:ComboBox>
                                        <ext:NumberField runat="server" ID="nfProjectYear" FieldLabel="Project Year<span style='color: Red;'>*</span>" AllowBlank="false"
                                            MaxValue="2500" MinValue="1900" MaxLength="4">
                                        </ext:NumberField>
                                        <ext:DisplayField runat="server" FieldLabel="Project Desc<span style='color: Red;'>*</span>" />
                                        <ext:HtmlEditor runat="server" ID="taProjectDesc" HideLabel="true" EnableFont="False" Height="138" EnableFontSize="False" EnableLinks="False"></ext:HtmlEditor>
                                    </Items>
                                </ext:FieldSet>
                            </Items>
                        </ext:Panel>
                        <ext:Panel ID="Panel1" runat="server" ColumnWidth="0.5" BodyStyle="background-color:transparent;border-color: #CCC;"
                            Layout="FormLayout" Border="False">
                            <Items>
                                <ext:FieldSet runat="server" Layout="RowLayout" Split="true" Height="360" Padding="8">
                                    <Items>
                                        <ext:Panel runat="server" BodyStyle="background-color:transparent;" RowHeight="0.5" Layout="HBoxLayout"
                                            Border="False" Split="true" >
                                            <Items>
                                                <ext:GridPanel ID="grdExpertise" runat="server" StripeRows="true" Height="160" AutoExpandColumn="ExpertiseName"
                                                    DisableSelection="True" EnableColumnHide="False" EnableColumnMove="False" EnableColumnResize="False"
                                                    HideHeaders="True" Title="Expertise" Flex="1" Margins="0 5 5 0">
                                                    <Store>
                                                        <ext:Store ID="storeExpertise" runat="server">
                                                            <Reader>
                                                                <ext:JsonReader IDProperty="ExpertiseId">
                                                                    <Fields>
                                                                        <ext:RecordField Name="ExpertiseId" />
                                                                        <ext:RecordField Name="ExpertiseName" />
                                                                        <ext:RecordField Name="Checked" Type="Boolean" />
                                                                    </Fields>
                                                                </ext:JsonReader>
                                                            </Reader>
                                                        </ext:Store>
                                                    </Store>
                                                    <ColumnModel ID="ColumnModel1" runat="server">
                                                        <Columns>
                                                            <ext:Column ColumnID="ExpertiseName" DataIndex="ExpertiseName" Header="ExpertiseName" />
                                                            <ext:CheckColumn Editable="true" ColumnID="Checked" DataIndex="Checked" Align="Center"
                                                                Width="30" />
                                                        </Columns>
                                                    </ColumnModel>
                                                </ext:GridPanel>
                                                <ext:Panel ID="Panel2" runat="server" Flex="1" BodyStyle="background-color:transparent;"
                                                    Region="Center" Layout="FormLayout" Title="Orther skill" Padding="5">
                                                    <Defaults>
                                                        <ext:Parameter Name="Anchor" Value="100%" />
                                                    </Defaults>
                                                    <Items>
                                                        <ext:TriggerField ID="tfAddSkill" runat="server" HideLabel="true">
                                                            <Triggers>
                                                                <ext:FieldTrigger Icon="SimplePlus" Qtip="Add skill" />
                                                                <ext:FieldTrigger Icon="SimpleError" Qtip="Clear all skill" />
                                                            </Triggers>
                                                            <Listeners>
                                                                <SpecialKey Fn="KeyEnterAdd" />
                                                                <TriggerClick Fn="tfAddSkillClick" />
                                                            </Listeners>
                                                        </ext:TriggerField>
                                                        <ext:TextArea ID="taOtherSkill" runat="server" Height="93" ReadOnly="true" HideLabel="true" />
                                                    </Items>
                                                </ext:Panel>
                                            </Items>
                                        </ext:Panel>
                                        <ext:GridPanel ID="gpStudent" RowHeight="0.5" runat="server" StripeRows="true" AutoExpandColumn="StudentName"
                                            EnableColumnHide="False" EnableColumnMove="False" EnableColumnResize="False"
                                            Title="Students participating in the project">
                                            <TopBar>
                                                <ext:Toolbar ID="tbStudent" runat="server">
                                                    <Items>
                                                        <ext:ComboBox ID="cbStudentID" runat="server" DisplayField="StudentId" ValueField="StudentId"
                                                            TypeAhead="false" ItemSelector="tr.list-item" MinChars="0" Width="150" SelectOnFocus="true"
                                                            TriggerAction="All" EnableKeyEvents="true" ListWidth="500">
                                                            <Store>
                                                                <ext:Store ID="stStudentSearch" runat="server" AutoLoad="true">
                                                                    <Proxy>
                                                                        <ext:HttpProxy Method="POST" Url="/Modules/List/Search.ashx" DisableCaching="true" AutoDataBind="true" />
                                                                    </Proxy>
                                                                    <Reader>
                                                                        <ext:JsonReader Root="Search" TotalProperty="total" IDProperty="StudentId">
                                                                            <Fields>
                                                                                <ext:RecordField Name="StudentId" />
                                                                                <ext:RecordField Name="SurName" />
                                                                                <ext:RecordField Name="GivenName" />
                                                                                <ext:RecordField Name="Gpa" />
                                                                                <ext:RecordField Name="ProjectType">
                                                                                    <Convert Fn="RendererProjectTypeS" />
                                                                                </ext:RecordField>
                                                                                <ext:RecordField Name="Comment" />
                                                                                <ext:RecordField Name="OtherSkill" />
                                                                                <ext:RecordField Name="Expertise" />
                                                                            </Fields>
                                                                        </ext:JsonReader>
                                                                    </Reader>
                                                                    <BaseParams>
                                                                        <ext:Parameter Name="type" Value="StudentLoadHaveProject" Mode="Value" />
                                                                        <ext:Parameter Name="haveProject" Value="false" Mode="Value" />
                                                                    </BaseParams>
                                                                </ext:Store>
                                                            </Store>
                                                            <Template ID="Template1" runat="server">
                                                                <Html>
                                                                <tpl for=".">
                                                                    <tpl if="[xindex] == 1">
                                                                        <table class="cbStates-list" width="100%">
                                                                    </tpl>
                                                                    <tr class="list-item">
                                                                        <td width="40px" style="padding:3px 0px;">{StudentId}</td>
                                                                        <td width="100px" style="padding:3px 0px;">{GivenName} {SurName}</td>
                                                                        <td width="30px" style="padding:3px 0px;">{Gpa}</td>
                                                                        <td width="100px" style="padding:3px 0px;">{Expertise}</td>
                                                                        <td width="100px" style="padding:3px 0px;">{ProjectType}</td>
                                                                        <td width="100px" style="padding:3px 0px;">{OtherSkill}</td>
                                                                        <td width="100px" style="padding:3px 0px;">{Comment}</td>
                                                                    </tr>
                                                                    <tpl if="[xcount-xindex]==0"> 
                                                                        </table>
                                                                    </tpl>
                                                                </tpl>
                                                                </Html>
                                                            </Template>
                                                            <Triggers>
                                                                <ext:FieldTrigger Icon="SimpleAdd" Qtip="Add student" />
                                                            </Triggers>
                                                            <Listeners>
                                                                <TriggerClick Fn="AddStudent" />
                                                            </Listeners>
                                                        </ext:ComboBox>
                                                        <ext:ToolbarFill />
                                                        <ext:ToolbarSpacer />
                                                        <ext:Button runat="server" ID="btnDelete" Text="Delete" Icon="Delete">
                                                            <Listeners>
                                                                <Click Fn="DeleteStudent" />
                                                            </Listeners>
                                                        </ext:Button>
                                                    </Items>
                                                </ext:Toolbar>
                                            </TopBar>
                                            <Store>
                                                <ext:Store ID="stStudent" runat="server">
                                                    <Reader>
                                                        <ext:JsonReader IDProperty="StudentId">
                                                            <Fields>
                                                                <ext:RecordField Name="StudentId" />
                                                                <ext:RecordField Name="SurName" />
                                                                <ext:RecordField Name="GivenName" />
                                                                <ext:RecordField Name="Gpa" />
                                                                <ext:RecordField Name="ProjectType" />
                                                                <ext:RecordField Name="Comment" />
                                                                <ext:RecordField Name="OtherSkill" />
                                                                <ext:RecordField Name="Expertise" />
                                                            </Fields>
                                                        </ext:JsonReader>
                                                    </Reader>
                                                </ext:Store>
                                            </Store>
                                            <ColumnModel ID="ColumnModel2" runat="server">
                                                <Columns>
                                                    <ext:Column ColumnID="StudentId" DataIndex="StudentId" Header="StudentId" />
                                                    <ext:Column ColumnID="StudentName" Header="StudentName">
                                                        <Renderer Handler="return record.data.GivenName + ' ' + record.data.SurName;" />
                                                    </ext:Column>
                                                </Columns>
                                            </ColumnModel>
                                            <SelectionModel>
                                                <ext:RowSelectionModel />
                                            </SelectionModel>
                                        </ext:GridPanel>
                                    </Items>
                                </ext:FieldSet>
                            </Items>
                        </ext:Panel>
                    </Items>
                </ext:Panel>
            </Items>
            <Listeners>
                <ClientValidation Handler="#{btnSave}.setDisabled(!valid);" />
            </Listeners>
        </ext:FormPanel>
    </Items>
    <Buttons>
        <ext:Button ID="btnNew" runat="server" Text="New" Icon="New">
            <DirectEvents>
                <Click OnEvent="btnNew_Click" />
            </DirectEvents>
        </ext:Button>
        <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
            <Listeners>
                <Click Fn="SaveData" />
            </Listeners>
        </ext:Button>
        <ext:Button ID="btnCancel" runat="server" Text="Cancel" Icon="Cancel">
            <Listeners>
                <Click Handler="#{winDetails}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
